// pages/message/index.js
import { timeTransform } from '../../utils/timeTransform.js'
let app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    loading: false,
    TabCur: 0,
    commentList: [],
    replyList: []
  },

  lookDetail(e) {
    // console.log(e.currentTarget.dataset.voiceid)
    wx.navigateTo({
      url: '/pages/detail/index?voiceid=' + e.currentTarget.dataset.voiceid,
    })
  },

  tabSelect(e) {
    this.setData({
      TabCur: e.currentTarget.dataset.id
    })
  },

  getMessageList(){
    this.setData({
      loading: true
    })
    wx.cloud.callFunction({
      name: 'getMessageList'
    }).then(res => {
      // console.log(res.result)
      let commentList = res.result.commentList
      let replyList = res.result.replyList
      commentList.forEach((item, index) => {
        if (app.mpOpenTime < item.commentDate){
          commentList[index].isNew = true
        }else{
          commentList[index].isNew = false
        }
        commentList[index].commentDate = timeTransform(item.commentDate)
      })
      replyList.forEach((item, index) => {
        if (app.mpOpenTime < item.replyDate) {
          replyList[index].isNew = true
        } else {
          replyList[index].isNew = false
        }
        replyList[index].replyDate = timeTransform(item.replyDate)
      })
      this.setData({
        commentList,
        replyList,
        loading: false
      })
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getMessageList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})